package cn.stylefeng.guns.modular.manager.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.manager.entity.FlowStoreCityNote;
import cn.stylefeng.guns.modular.manager.entity.FlowStoreRegion;
import cn.stylefeng.guns.modular.manager.mapper.FlowStoreRegionMapper;
import cn.stylefeng.guns.modular.manager.model.params.FlowStoreCityNoteParam;
import cn.stylefeng.guns.modular.manager.model.params.FlowStoreRegionParam;
import cn.stylefeng.guns.modular.manager.model.result.FlowStoreRegionResult;
import cn.stylefeng.guns.modular.manager.service.FlowStoreRegionService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;
@Service
public class FlowStoreRegionServiceImpl extends ServiceImpl<FlowStoreRegionMapper, FlowStoreRegion> implements FlowStoreRegionService {
    @Override
    public void add(FlowStoreRegionParam param) {
        FlowStoreRegion entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(FlowStoreRegionParam param) {
        this.removeById(getKey(param));
    }

    @Override
    public void update(FlowStoreRegionParam param) {
        FlowStoreRegion oldEntity = getOldEntity(param);
        FlowStoreRegion newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public FlowStoreRegionResult findBySpec(FlowStoreRegionParam param) {
        return null;
    }

    @Override
    public List<FlowStoreRegionResult> findListBySpec(FlowStoreRegionParam param) {
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(FlowStoreRegionParam param) {
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param);
        return LayuiPageFactory.createPageInfo(page);
    }

    private FlowStoreRegion getEntity(FlowStoreRegionParam param) {
        FlowStoreRegion entity = new FlowStoreRegion();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

    private Serializable getKey(FlowStoreRegionParam param){
        return param.getRegionId();
    }

    private FlowStoreRegion getOldEntity(FlowStoreRegionParam param) {
        return this.getById(getKey(param));
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }
}
